<?php
// +----------------------------------------------------------------------
// | SparkShop 坚持做优秀的商城系统
// +----------------------------------------------------------------------
// | Copyright (c) 2022~2099 http://sparkshop.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: NickBai  <1902822973@qq.com>
// +----------------------------------------------------------------------
namespace app\api\controller;

use app\BaseController;
use app\service\GoodsService;

class Goods extends BaseController
{
    public function initialize()
    {
        crossDomain();
    }

    /**
     * 商品详情
     */
    public function detail(GoodsService $goodsService)
    {
        return json($goodsService->getMobileGoodsDetail(input('param.id')));
    }

    /**
     * 商品规格详情
     */
    public function goodsRuleDetail(GoodsService $goodsService)
    {
        return json($goodsService->getGoodsRuleDetail(input('param.sku'), input('param.goods_id')));
    }

    /**
     * 获取商品评论
     */
    public function getComments(GoodsService $goodsService)
    {
        return json($goodsService->getComments(input('param.')));
    }

    /**
     * 获取分类下的商品
     */
    public function getGoodsByCateInfo(GoodsService $goodsService)
    {
        return json($goodsService->getGoodsByCateId(input('param.')));
    }
    /**
     * 获取商品的广告
     */
    public function getGoodsAD(GoodsService $goodsService)
    {
        $goodsList = $goodsService->getGoodsAD(input('param.'));
        $param = input('param.');
        $openid = '';
        if(isset($param['openid'])){
            $openid = $param['openid'];
        }
        if($goodsList){
            $showhtml = '';
            foreach($goodsList as $k=>$v){
                if($v['id'] > 0){
                    $showhtml.="<div style='padding:5px 2%; width:96%;position: relative;display: inline-block;'><a href ='https://s.xinmago.cn/h5/#/pages/product/product?id=".$v['id']."&openid=".$openid."'><div style='position: absolute;top: 5px;right: 2%;background-color: rgba(0, 0, 0, 0.2); color: #888888; font-weight:800;padding: 5px 15px;border-radius:0px 5px 0px 8px'>广告</div><img src = '".$v['banner_src']."' style='width:100%'/></a></div>"; 
                }else{
                    $showhtml.="<div style='padding:5px 2%; width:96%;position: relative;display: inline-block;'><a href ='https://s.xinmago.cn/h5/#/?id=".$v['id']."&openid=".$openid."'><div style='position: absolute;top: 5px;right: 2%;background-color: rgba(0, 0, 0, 0.2); color: #888888; font-weight:800;padding: 5px 15px;border-radius:0px 5px 0px 8px'>广告</div><img src = '".$v['banner_src']."' style='width:100%'/></a></div>"; 
                }
                
            }
        }
        echo 'document.write("'.$showhtml.'");';
    }
}